
	class Rectangle
	{
		private _x:number;
		private _y:number;
		private _left:number;
		private _right:number;
		private _top:number;
		private _bottom:number;
		private _width:number;
		private _height:number;
		private _topLeft:Laya.Point;
		private _bottomRight:Laya.Point;
		public constructor(x:number=0,y:number=0,w:number=0,h:number=0)
		{var s = this;
			s._x = x;
			s._y = y;
			s._left = x;
			s._right = x + w;
			s._top = y;
			s._bottom = y + h;
			s._width = w;
			s._height = h;
			s._topLeft = new Laya.Point(s._left,s._top);
			s._bottomRight = new Laya.Point(s._right,s._bottom);
		}
		public set x(x:number)
		{var s = this;
			s._x = x;
			s._left = x;
			// s._width = s._right - x;
			s._right = x + s._width;
			s._topLeft.x = s._left;		
		}
		public get x():number
		{var s = this;
			return s._x;
		}
		
		public set y(y:number)
		{var s = this;
			s._y = y;		
			s._top = y;		
			//s._height = s._bottom - y;
			s._bottom = y + s._height;
			s._topLeft.y = s._top;		
		}
		public get y():number
		{var s = this;
			return s._y;
		}
		
		public set left(left:number)
		{var s = this;
			s.x = left;
		}
		public get left():number
		{var s = this;
			return s._left;
		}
		
		public set top(top:number)
		{var s = this;
			s.y = top;
		}
		public get top():number
		{var s = this;
			return s._top;
		}
		
		public set right(right:number)
		{var s = this;
			s._right = right;
			s._width = s._right - s._x;
			s._topLeft.y = s._left;
		}
		public get right():number
		{var s = this;
			return s._right;
		}
		
		public set bottom(bottom:number)
		{var s = this;
			s._bottom = bottom;
			s._height = s._bottom - s._y;
			s._bottomRight.y = s._bottom;
		}
		public get bottom():number
		{var s = this;
			return s._bottom;
		}
		
		public set width(w:number)
		{var s = this;
			s._width = w;
			s._right = s.x + w;
			s._bottomRight.x = s._right;
		}
		public get width():number
		{var s = this;
			return s._width;
		}
		public set height(h:number)
		{var s = this;
			s._height = h;
			s._bottom = s._y + h;		
			s._bottomRight.y = s._bottom;
		}
		public get height():number
		{var s = this;
			return s._height;
		}
		public get topLeft():Laya.Point
		{return this._topLeft;}
		get bottomRight():Laya.Point
		{return this._bottomRight;}
		public clone()
		{var s = this;
			new Rectangle(s._x,s._y,s._width,s._height);
		}
		public copyForm(sr:Rectangle):void
		{let s = this;
			s.x = sr.x;
			s.y = sr.y;
			s.width = sr.width;
			s.height = sr.height;
		}
		public contain(x,y):boolean
		{let s = this;
			return s._x <= x && s._right >= x && s._y <= y && s._bottom >= y;
		}
		public containPoint(p:Laya.Point):void
		{var s = this;
			s.contain(p.x,p.y);
		}
		public containRect(sr:Rectangle):boolean
		{var s = this;
			return s._x <= sr.x && s._right >= sr.x && s._y <= sr.y && s._bottom >= sr.y && s._x <= sr.right && s._right >= sr.right && s._y <= sr.bottom && s._bottom >= sr.bottom;
		}
		public equals(sr:Rectangle):boolean
		{var s = this;
			return s.x == sr.x && s.y == sr.y && s.bottom == sr.bottom && s.right == sr.right;
		}
		public inflate(dx:number,dy:number):void
		{var s = this;
			s.width += dx;
			s.height += dy;
		}
		public inflatePoint(p:Laya.Point):void
		{var s = this;
			s.width += p.x;
			s.height += p.y;
		}
		public intersection(toIntersect:Rectangle):Rectangle
		{var s = this;		
			let rect = new Rectangle;
			if(s._left > toIntersect._right || toIntersect.left > s._right || s._top > toIntersect._bottom || toIntersect._top > s._bottom)return rect;
			rect.left = s._left > toIntersect.left?s._left:toIntersect.left;
			rect.top = s._top > toIntersect.top?s._top:toIntersect.top;
			rect.right = s._right < toIntersect.right?s._right:toIntersect.right;
			rect.bottom = s._bottom < toIntersect.bottom?s._bottom:toIntersect.bottom;
			return rect;
		}
		public intersecs(toIntersect:Rectangle):boolean
		{var s = this;
			return s._left > toIntersect._right || toIntersect.left > s._right || s._top > toIntersect._bottom || toIntersect._top > s._bottom;	
		}
		public isEmpty():boolean
		{let s = this;
			return s.width <= 0 && s.height <= 0;
		}		
		public offsetPoint(p:Laya.Point):void
		{var s = this;
			s.x = p.x;
			s.y = p.y;
		}
		public setEmpty():void
		{var s = this;
			s.x = s.y = s.width = s.height = 0;
		}
		public setTo(xa:number, ya:number, widtha:number, heighta:number):void
		{var s = this;
			s.x = xa;
			s.y = ya;
			s.width = widtha;
			s.height = heighta;
		}
		public union(toUnion:Rectangle):Rectangle
		{var s = this;
			let rect = new Rectangle;		
			rect.left = s._left < toUnion.left?s._left:toUnion.left;
			rect.top = s._top < toUnion.top?s._top:toUnion.top;
			rect.right = s._right > toUnion.right?s._right:toUnion.right;
			rect.bottom = s._bottom > toUnion.bottom?s._bottom:toUnion.bottom;
			return rect;
		}
		public static rectToLaya(rect:Rectangle):Laya.Rectangle
		{
			let r:Laya.Rectangle;
			if(rect)
				r = new Laya.Rectangle(rect.x,rect.y,rect.width,rect.height);
			return r;			
		}
		public static layaToRect(layaRect:Laya.Rectangle):Rectangle
		{
			let r:Rectangle;
			if(layaRect)
				r = new Rectangle(layaRect.x,layaRect.y,layaRect.width,layaRect.height);
			return r;	
		}
	}
